<?php


namespace app\adminapi\validate\system;


use app\common\model\member\MemberLevel;
use app\common\model\system\SysMenu;
use app\common\validate\BaseValidate;

/**
 * @projectName src
 */
class SysMenuValidate extends BaseValidate
{
    protected $rule = [
        'id' => 'require|checkSysMenu',
        'menu_type' => 'require',
        'menu_name' => 'require',
        'parent_id' => 'require|integer|checkParentMenu',
        'menu_order'=>'require|integer',
        'menu_status'=>'require|integer|in:0,1',
        'menu_show'=>'require|integer|in:0,1',
        'is_target'=>'require|integer|in:0,1',
    ];

    protected $message = [
        'id.require' => '参数缺失',
        'menu_type.require' => '请填写菜单类型',
        'menu_name.require' => '请填写菜单名称',
        'parent_id.require' => '请填写父级id',
        'parent_id.integer' => '父级id参数不合法',
        'menu_order.require' => '请填写菜单排序',
        'menu_order.integer' => '菜单排序参数不合法',
        'menu_status.require' => '请填写菜单状态',
        'menu_status.integer'=>'菜单状态参数不合法',
        'menu_status.in:0,1'=>'菜单状态参数不合法',
        'menu_show.require' => '请填写菜单状态',
        'menu_show.integer'=>'菜单状态参数不合法',
        'menu_show.in:0,1'=>'菜单状态参数不合法',
        'is_target.require' => '请填写菜单状态',
        'is_target.integer'=>'菜单状态参数不合法',
        'is_target.in:0,1'=>'菜单状态参数不合法',
    ];

    /**
     * @notes 添加场景
     * sceneAdd
     */
    public function sceneAdd()
    {
        return $this->only(['menu_type','menu_name','parent_id']);
    }

    /**
     * @notes 详情场景
     * sceneAdd
     */
    public function sceneDetail()
    {
        return $this->only(['id']);
    }

    /**
     * @notes 编辑场景
     * sceneAdd
     */
    public function sceneEdit()
    {
    }

    /**
     * @notes 删除场景
     * sceneAdd
     */
    public function sceneDelete()
    {
        return $this->only(['id']);
    }

    public function checkSysMenu($value)
    {
        $sysMenu = SysMenu::findOrEmpty($value);
        if ($sysMenu->isEmpty()) {
            return '菜单不存在';
        }
        return true;
    }

    public function checkParentMenu($value)
    {
        $parentMenu = SysMenu::findOrEmpty($value);
        if($parentMenu->isEmpty()){
            return "父级菜单不存在";
        }
        return true;
    }
}